package com.qubuyer.business.home.adapter

import com.qubuyer.R
import com.qubuyer.repository.entitys.CategoryFirstEntity
import com.qubuyer.repository.entitys.CategorySecondEntity
import com.qubuyer.business.category.activity.SecondCategoryActivity
import com.qubuyer.databinding.ItemHomeCategorySecondBinding
import com.qubuyer.repository.entitys.HomeCategoryEntity
import com.qubuyer.utils.NavigationUtil
import com.qubyer.widget.adapter.BindingRvAdapter
import java.util.*

class HomeCategoryAdapter(dataList: ArrayList<HomeCategoryEntity>) : BindingRvAdapter<HomeCategoryEntity, ItemHomeCategorySecondBinding>(dataList) {
    override val itemLayout: Int
        get() = R.layout.item_home_category_second

    override fun onBind(data: HomeCategoryEntity, dataBinding: ItemHomeCategorySecondBinding) {
        dataBinding.host = this
        dataBinding.data = data
        dataBinding.root.setOnClickListener { onItemClick(data) }
    }

    private fun onItemClick(data: HomeCategoryEntity) {
        val map: HashMap<String, Any?> = HashMap()
        val categoryFirstEntity = CategoryFirstEntity()
        categoryFirstEntity.id = data.id
        categoryFirstEntity.name = data.name
        map["first_category_entity"] = categoryFirstEntity
        val secondCategoryGoodEntity = CategorySecondEntity()
        secondCategoryGoodEntity.id = data.id
        map["second_category_entity"] = secondCategoryGoodEntity
        NavigationUtil.overlay(mContext, SecondCategoryActivity::class.java, map)
    }
}